//
//  DKLoginVoiceAlertView.m
//  DanKU
//
//  Created by 吴斌 on 2023/11/5.
//

#import "DKLoginVoiceAlertView.h"

@interface DKLoginVoiceAlertView()
@property (nonatomic, weak)zhPopupController * dk_LoginVoiceAlertViewPop;
@property (nonatomic,strong) DKLoginVoiceAlertView *dk_LoginVoiceAlertView;
@property (nonatomic, assign)BOOL isDisMiss;
@property (nonatomic, copy)  void(^SureVoiceVerificaBlock)(void);
@property (nonatomic, copy) void(^SureSMSVerificaBlock)(void);
@end
@implementation DKLoginVoiceAlertView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.whiteColor;
        self.layer.cornerRadius = 50;
        self.clipsToBounds = YES;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    UILabel *dk_LoginAgreenHeadLab = [[UILabel alloc] init];
    dk_LoginAgreenHeadLab.textColor = DK_Hex(@"#333333");
    dk_LoginAgreenHeadLab.font = DK_FONT_Semibold(17);
    dk_LoginAgreenHeadLab.text = @"Tips";
    [self addSubview:dk_LoginAgreenHeadLab];
    [dk_LoginAgreenHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(24)));
        make.centerX.equalTo(self);
    }];
    UILabel *dk_LoginalertLab = [[UILabel alloc] init];
    dk_LoginalertLab.textColor = DK_Hex(@"#333333");
    dk_LoginalertLab.font = DK_FONT_Regular(14);
    dk_LoginalertLab.text = @"If you can not recieve SMS verification code, try voice verificaition, please pay attention to your phone calls.";
    dk_LoginalertLab.numberOfLines = 0;
    [self addSubview:dk_LoginalertLab];
    [dk_LoginalertLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dk_LoginAgreenHeadLab.mas_bottom).offset(DK_IsWidthScale(19));
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
    }];

    //Voice verification
    UIButton * dk_LoginVoiceVerificationtBtn = [[UIButton alloc] init];
    [dk_LoginVoiceVerificationtBtn setTitle:@"Voice verification" forState:UIControlStateNormal];
    [dk_LoginVoiceVerificationtBtn setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
    dk_LoginVoiceVerificationtBtn.titleLabel.font = DK_FONT_Semibold(16);
    [dk_LoginVoiceVerificationtBtn setBackgroundColor:DK_Hex(@"#4566FF")];
    dk_LoginVoiceVerificationtBtn.layer.cornerRadius = DK_IsWidthScale(25);
    dk_LoginVoiceVerificationtBtn.clipsToBounds = YES;
    [dk_LoginVoiceVerificationtBtn addTarget:self action:@selector(voiceVerification) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_LoginVoiceVerificationtBtn];
    [dk_LoginVoiceVerificationtBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.top.equalTo(dk_LoginalertLab.mas_bottom).offset(DK_IsWidthScale(46));
    }];
    //close
    UIButton * dk_LoginSMSVerificationtBtn = [[UIButton alloc] init];
    [dk_LoginSMSVerificationtBtn setTitle:@"SMS verification" forState:UIControlStateNormal];
    [dk_LoginSMSVerificationtBtn setTitleColor:DK_Hex(@"#4566FF") forState:UIControlStateNormal];
    dk_LoginSMSVerificationtBtn.titleLabel.font = DK_FONT_Semibold(16);
    [dk_LoginSMSVerificationtBtn setBackgroundColor:DK_Hex(@"#F0F2FF")];
    dk_LoginSMSVerificationtBtn.layer.cornerRadius = DK_IsWidthScale(25);
    dk_LoginSMSVerificationtBtn.clipsToBounds = YES;
    [dk_LoginSMSVerificationtBtn addTarget:self action:@selector(smsVerification) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_LoginSMSVerificationtBtn];
    [dk_LoginSMSVerificationtBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.top.equalTo(dk_LoginVoiceVerificationtBtn.mas_bottom).offset(DK_IsWidthScale(10));
    }];
    
    //close
    UIButton * dk_LoginCloseBtn = [[UIButton alloc] init];
    [dk_LoginCloseBtn setBackgroundImage:DK_GetImage(@"dk_LoginAgreementClose") forState:UIControlStateNormal];
    [dk_LoginCloseBtn addTarget:self action:@selector(goCancle) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_LoginCloseBtn];
    [dk_LoginCloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(20)));
        make.right.equalTo(@(-DK_IsWidthScale(20)));
        make.height.equalTo(@(DK_IsWidthScale(17)));
        make.width.equalTo(@(DK_IsWidthScale(17)));
    }];
}
- (void)voiceVerification{
    if(self.checkVoiceBlock){
        self.checkVoiceBlock();
        if(_isDisMiss){
            [_dk_LoginVoiceAlertViewPop dismiss];
        }
    }
}
- (void)smsVerification{
    if(self.checkSMSBlock){
        self.checkSMSBlock();
        if(_isDisMiss){
            [_dk_LoginVoiceAlertViewPop dismiss];
        }
    }
}
- (void)goCancle{
    [_dk_LoginVoiceAlertViewPop dismiss];
}
+ (void)dk_ShowVoiceAlertViewNextCompleteIsDismiss:(BOOL)isDisMiss withVoice:(void(^)(void))checkVoiceBlock WithSms:(void(^)(void))checkSMSBlock{
    DKLoginVoiceAlertView * dk_LoginVoiceAlertView = [[DKLoginVoiceAlertView alloc] init];
    zhPopupController * sureAgreemnetCtrl = [[zhPopupController alloc] initWithView:dk_LoginVoiceAlertView size:CGSizeMake(DK_SCREEN_W - DK_IsWidthScale(60), DK_IsWidthScale(329))];
    dk_LoginVoiceAlertView.checkVoiceBlock = checkVoiceBlock;
    dk_LoginVoiceAlertView.checkSMSBlock = checkSMSBlock;
    dk_LoginVoiceAlertView.isDisMiss = isDisMiss;
    sureAgreemnetCtrl.presentationStyle = zhPopupSlideStyleTransform;
    sureAgreemnetCtrl.layoutType = zhPopupLayoutTypeCenter;
    sureAgreemnetCtrl.presentationTransformScale = 0.56;
    sureAgreemnetCtrl.dismissonTransformScale = 0.56;
    sureAgreemnetCtrl.dismissOnMaskTouched = NO;
    dk_LoginVoiceAlertView.dk_LoginVoiceAlertViewPop = sureAgreemnetCtrl;
    [sureAgreemnetCtrl showInView:((AppDelegate*)([UIApplication sharedApplication].delegate)).window completion:^{
    }];
}
@end
